#include "hc32_ddl.h"
#include <rtthread.h>





int  usart_send_msg(uint8_t * msg,uint16_t len);
uint8_t uart_rx_buffer[512];
extern rt_sem_t uart_control_handle;
int uart_send_msg(uint8_t * msg ,int len);


void uart_rx_thread(void * arg)
{

  uint8_t len = 0;
 while(1)
 {   
   if(rt_sem_take(uart_control_handle,RT_WAITING_FOREVER) == RT_EOK)
   {
     len = get_uart_fifo_msg(uart_rx_buffer);
     
     uart_send_msg(uart_rx_buffer,len);
     
   }
 }
}



int uart_send_msg(uint8_t * msg ,int len)
{
  usart_send_msg(msg,len);
  return len;
}


int init_uart_rx_tx(void)
{

  rt_thread_t uart_hande_t = rt_thread_create("uart_rec",uart_rx_thread,0,1024,12,10);
  if(uart_hande_t)
  {
    rt_thread_startup(uart_hande_t);
  }
  return 0;
}

INIT_APP_EXPORT(init_uart_rx_tx);